﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Control_NopTaiKhoan : System.Web.UI.UserControl
{
    XuLy xl = new XuLy();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
          
            if (Session["DangNhap"] != null)
            {
                lbKhachHang.Text = Session["DangNhap"].ToString();
                //lbTaiKhoan.Text = Session["DangNhap"].ToString();
                // lay tai khoan hien co cua khach hang 
                DataTable taikhoan = xl.Load("select taikhoan from khachhang where tendn='" + Session["DangNhap"].ToString() + "'");
                string tkCon = Convert.ToString(taikhoan.Rows[0][0].ToString());
                lbTaiKhoan.Text = tkCon;
            }
        }
    }
    protected void btnHuy_Click(object sender, EventArgs e)
    {
        lbKhachHang.Text = Session["DangNhap"].ToString();
        //lbTaiKhoan.Text = Session["DangNhap"].ToString();
        // lay tai khoan hien co cua khach hang 
        DataTable taikhoan = xl.Load("select taikhoan from khachhang where tendn='" + Session["DangNhap"].ToString() + "'");
        lbTaiKhoan.Text = taikhoan.ToString();
        txtNopTaiKhoan.Text = "";
    }
    protected void btnDongY_Click(object sender, EventArgs e)
    {
        // lay tai khoan cua khach hang 
        DataTable taikhoan = xl.Load("select taikhoan from khachhang where tendn='" + Session["DangNhap"].ToString() + "'");
        double taikhoankhach = Convert.ToDouble(taikhoan.Rows[0][0].ToString());
        double tienthem = taikhoankhach;
        int sotienthem = int.Parse(txtNopTaiKhoan.Text);
        tienthem = taikhoankhach +sotienthem;
        string query4 = "update Khachhang set taikhoan=" + tienthem + " where tendn='" + Session["DangNhap"].ToString() + "'";
        xl.XuLyDuLieu(query4);
        Response.Redirect("BaoLoi.aspx?mod=ThemTien");

    }
}